package com.course.business.controller;

import com.course.server.dto.ResponseDto;
import com.course.server.exception.ValidatorException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * ClassName: ControllerExceptionHandler
 * Description:
 * date: 2021/8/25 16:45
 *
 * @author 17878
 * @since JDK 1.8
 */
@Slf4j
@ControllerAdvice//进行异常处理的一个注解
public class ControllerExceptionHandler {
    @ExceptionHandler(value =ValidatorException.class)
    @ResponseBody//要以json形式返回回去，所以用responsebody
    public ResponseDto validatorExceptionHandler(ValidatorException e){
        ResponseDto responseDto=new ResponseDto();
        responseDto.setSuccess(false);
        log.warn(e.getMessage());
        responseDto.setMessage("请求参数异常");
        return responseDto;
    }
}
